package com.azzcs.customer.utils;


import com.azzcs.spring.anno.Autowired;
import com.azzcs.spring.anno.Component;
import com.azzcs.spring.bean.TransactionManager;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Author: wzg
 * @Date: 2020/12/13 下午5:34
 */
@Component
public class MyTransactionManager implements TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    public void open() throws SQLException {
        Connection connection = connectionUtils.getConnection();
        connection.setAutoCommit(false);
    }

    public void commit() throws SQLException {
        Connection connection = connectionUtils.getConnection();
        connection.commit();
    }

    public void rollback() throws SQLException {
        Connection connection = connectionUtils.getConnection();
        connection.rollback();
    }

}
